import time


def write_txt():
    date = time.localtime()
    date = time.strftime('%Y-%m-%d %H:%M:%S', date)
    text = input("请输入日记内容：")
    filename = '日记本.txt'
    with open(filename, mode='a', encoding='utf-8') as f:
        f.write('pyrjb\n')  # 用于分隔的特殊记号
        f.write(date+'\n')
        f.write(text+'\n')
        return True


def read_txt(day='-1'):
    filename = '日记本.txt'
    with open(filename, mode='r', encoding='utf-8') as f:
        content = f.read()
        if day != '-1':
            content = content.split('pyrjb\n')
            for i in content:
                if i[:10:] == day:
                    print(i.strip())
            return True
        else:
            content = content.replace('pyrjb\n', '')
            print(content)
        return True


def menu():
    print('*' * 30)
    print('''欢迎使用Python日记本系统
    1：记日记
    2：读取日记
    3：退出系统''')
    print('*' * 30)


def quit1():
    print("欢迎再次使用Python日记本系统！")


def my_diary():
    menu()
    while True:
        op = input("请输入你的选择：")
        if op == '1':
            if write_txt():
                print('日记保存成功！')
        elif op == '2':
            day = input('请输入你查询的日期（格式2025-03-13）(查询全部请输入-1):')
            if read_txt(day):
                print("日记加载完毕！")
            else:
                print('未查询到日记信息，请重试！')
        elif op == '3':
            quit1()
            break
        else:
            print('你的输入有误，请重新输入！')
